<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Product;
use App\Models\ProductCategory;
use App\Models\ProductTag;
use App\Models\Tag;
use App\Models\Team;
use App\Repositories\BannerRepository;
use App\Repositories\ProductRepository;
use App\Repositories\QuestionRepository;
use App\Repositories\TeamRepository;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    public function index(Request $request){


        $product = Product::with('font');


        $products = $product->where('status',1)->orderBy('id','desc')->paginate(10);
        $videoProduct = [];

        if($request->ajax()){

            return view('web.product.ajax-goods',compact('products','videoProduct'));
        }

        $teams = app(TeamRepository::class)->get();

        $queue_title = '';


        return view('web.product.index',compact('products','teams','queue_title','videoProduct'));
    }


    public function show($id){

        $goods = Product::with(['team','category'=>function($query){
            $query->with('parent');
        }])->where('id',$id)->where('status',1)->first();


        if(!$goods){
            abort(404);
        }


        $questions = app(QuestionRepository::class)->get();
        return view('web.product.show',compact('goods','questions'));
    }
}
